<template>
    <view>
        <view class="loadinggif" v-if="isloading">
            <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/loading.gif"></image>
        </view>
        <block v-if="!isloading">
            <view class="head" :style="'background:' + color">
                <view class="zwzh">类型：{{ type_name }}，桌号：{{ table_name }}</view>
                <button class="tjdcr flex-row flex-x-center flex-y-center" openType="share" :style="'color:' + color">
                    <view :style="'border:5rpx solid ' + color">+</view>
                    <view>添加拼单人</view>
                </button>
            </view>
            <view class="main">
                <view class="pdlist">
                    <view class="pdlisttop flex-row">
                        <image :src="drlsit.user.user_img"></image>
                        <view class="flex-grow-1">
                            <view class="flex-row">
                                <view class="flex-grow-1 gobyndsingle name">
                                    {{ drlsit.user.user_name }}
                                    <text class="fquser">发起人</text>
                                </view>
                                <navigator class="cxxg" :url="'smdcxgsp?storeid=' + storeid + '&zuid=' + zuid + '&dr_id=' + drid + '&tableid=' + tableid">重新选购</navigator>
                            </view>
                            <view class="pdlistfot flex-row flex-y-center" v-for="(item, index) in drlsit.user.good" :key="index">
                                <view class="flex-grow-1 flex-row flex-y-center">
                                    <view class="flex-grow-1">
                                        <view>{{ item.name }}</view>
                                        <view class="spec">{{ item.spec }}</view>
                                    </view>
                                    <view class="num">x{{ item.num }}</view>
                                </view>

                                <view class="money">￥{{ item.money }}</view>
                            </view>
                        </view>
                    </view>
                </view>
                <view class="pdlist" v-for="(sonitem, index) in drlsit.son" :key="index">
                    <view class="pdlisttop flex-row">
                        <image :src="sonitem.user_img"></image>
                        <view class="flex-grow-1">
                            <view class="flex-row">
                                <view class="flex-grow-1 gobyndsingle name">{{ sonitem.user_name }}</view>
                                <view @tap="sc" class="del" :data-sonid="sonitem.son_id">删除Ta</view>
                            </view>
                            <view class="pdlistfot flex-row flex-y-center" v-for="(item, index1) in sonitem.good" :key="index1">
                                <view class="flex-grow-1 flex-row flex-y-center">
                                    <view class="flex-grow-1">
                                        <view>{{ item.name }}</view>
                                        <view class="spec">{{ item.spec }}</view>
                                    </view>
                                    <view class="num">x{{ item.num }}</view>
                                </view>

                                <view class="money">￥{{ item.money }}</view>
                            </view>
                        </view>
                    </view>
                </view>
                <view class="hjsp">
                    <text>{{ drlsit.people }}人,</text>
                    <text>{{ drlsit.good_num }}份商品</text>
                </view>
            </view>
            <view class="dbtjdd flex-row flex-y-center">
                <view class="dbtjddl flex-row flex-y-center">
                    <view class="flex-grow-1">
                        合计
                        <text>￥{{ drlsit.money }}</text>
                    </view>
                </view>
                <view class="dbtjddr">
                    <form @reset="formReset" @submit="tjddformSubmit" :reportSubmit="true">
                        <button formType="submit" :style="'background:' + color">提交订单</button>
                    </form>
                </view>
            </view>
        </block>
        <button @tap="sxsj" class="hddb">
            <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/shuaxin.png"></image>
        </button>
        <view class="sdcg" v-if="drlsit.drorder.state == 2">
            <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/suo.png"></image>
            <view>订单已锁定</view>
            <button @tap="jsdd">解锁并继续拼单</button>
        </view>
        <view class="sdcg" style="z-index: 1100" v-if="drlsit.drorder.state == 3">
            <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/suo.png"></image>
            <view>拼单已结束</view>
        </view>
    </view>
</template>

<script>
import cardlist from '@/ymq_canyino2o/dist/cardlist/index';
import gettel from '@/ymq_canyino2o/dist/gettel/index';
var app = getApp();
var util = require('../../utils/util.js');
export default {
    components: {
        cardlist,
        gettel
    },
    data() {
        return {
            isloading: true,
            storeid: '',
            tableid: '',
            zuid: '',
            type_name: '',
            table_name: '',

            drlsit: {
                user: {
                    user_img: '',
                    good: []
                },

                son: [],
                people: '',
                good_num: '',
                money: '',

                drorder: {
                    state: 0
                }
            },

            drid: '',
            color: '',

            sonitem: {
                user_img: '',
                user_name: '',
                son_id: '',
                good: []
            }
        };
    },
    onLoad: function (e) {
        uni.hideShareMenu({});
        var that = this;
        var s = uni.getStorageSync('users').id;
        console.log(s, e);
        app.globalData.setNavigationBarColor(this);
        this.setData({
            storeid: e.storeid,
            tableid: e.tableid,
            zuid: s
        });
        app.globalData.util.request({
            url: 'entry/wxapp/Zhuohao',
            cachetime: '0',
            data: {
                id: e.tableid
            },
            success: function (t) {
                console.log(t);
                that.setData({
                    type_name: t.data.type_name,
                    table_name: t.data.table_name
                });
            }
        });
        app.globalData.util.request({
            url: 'entry/wxapp/IsDr',
            cachetime: '0',
            data: {
                store_id: e.storeid,
                user_id: s
            },
            success: function (t) {
                console.log(t.data);
                var a = t.data;
                if ('请重新开启拼单' != t.data) {
                    that.setData({
                        isloading: false
                    });
                    app.globalData.util.request({
                        url: 'entry/wxapp/DrShopList',
                        cachetime: '0',
                        data: {
                            store_id: e.storeid,
                            user_id: s,
                            dr_id: a
                        },
                        success: function (t) {
                            console.log(t.data);
                            that.setData({
                                drlsit: t.data,
                                drid: a
                            });
                        }
                    });
                } else {
                    app.globalData.util.request({
                        url: 'entry/wxapp/DrShop',
                        cachetime: '0',
                        data: {
                            store_id: e.storeid,
                            user_id: s
                        },
                        success: function (t) {
                            console.log(t.data);
                            var a = t.data;
                            if ('请稍后重试' != t.data) {
                                that.setData({
                                    isloading: false
                                });
                                app.globalData.util.request({
                                    url: 'entry/wxapp/DrShopList',
                                    cachetime: '0',
                                    data: {
                                        store_id: e.storeid,
                                        user_id: s,
                                        dr_id: a
                                    },
                                    success: function (t) {
                                        console.log(t.data);
                                        that.setData({
                                            drlsit: t.data,
                                            drid: a
                                        });
                                    }
                                });
                            }
                        }
                    });
                }
            }
        });
    },
    onReady: function () {},
    onShow: function () {},
    onHide: function () {},
    onUnload: function () {},
    onPullDownRefresh: function () {},
    onReachBottom: function () {},
    onShareAppMessage: function (t) {
        var a = this.storeid;
        var e = uni.getStorageSync('users').id;
        var o = this.tableid;
        var s = this.drid;
        console.log(a, e, o, s);
        if ('button' === t.from) {
            console.log(t.target);
        }
        return {
            title: uni.getStorageSync('users').name + '邀请你来拼单',
            path: '/ymq_canyino2o/pages/smdc/sharedrdc?storeid=' + a + '&tableid=' + o + '&uid=' + e + '&drid=' + s
        };
    },
    onShareTimeline: function (t) {
        var a = this.storeid;
        var e = uni.getStorageSync('users').id;
        var o = this.tableid;
        var s = this.drid;
        console.log(a, e, o, s);
        if ('button' === t.from) {
            console.log(t.target);
        }
        return {
            title: uni.getStorageSync('users').name + '邀请你来拼单',
            path: '/ymq_canyino2o/pages/smdc/sharedrdc?storeid=' + a + '&tableid=' + o + '&uid=' + e + '&drid=' + s
        };
    },
    methods: {
        qxpd: function () {
            var a = this.drid;
            var t = this.drlsit.drorder;
            console.log(t);
            uni.showModal({
                title: '提示',
                content: '是否关闭此拼单？',
                success: function (t) {
                    if (t.confirm) {
                        console.log('用户点击确定');
                        uni.showLoading({
                            title: '加载中'
                        });
                        app.globalData.util.request({
                            url: 'entry/wxapp/SdDrShop',
                            cachetime: '0',
                            data: {
                                id: a
                            },
                            success: function (t) {
                                console.log(t.data);
                                if ('1' == t.data) {
                                    uni.showToast({
                                        title: '取消成功'
                                    });
                                    uni.navigateBack({});
                                }
                            }
                        });
                    } else {
                        if (t.cancel) {
                            console.log('用户点击取消');
                        }
                    }
                }
            });
        },

        tjddformSubmit: function () {
            var that = this;
            var e = this.drid;
            var t = this.drlsit.drorder;
            console.log(t);
            if (this.drlsit.money <= 0) {
                uni.showModal({
                    title: '提示',
                    content: '金额过低无法提交订单'
                });
                return false;
            }
            if (2 == t.state) {
                uni.navigateTo({
                    url: 'smdcform?storeid=' + that.storeid + '&tableid=' + that.tableid + '&drid=' + e
                });
            }
            if (1 == t.state) {
                uni.showModal({
                    title: '提示',
                    content: '提交订单后将锁定订单',
                    success: function (t) {
                        if (t.confirm) {
                            console.log('用户点击确定');
                            uni.showLoading({
                                title: '加载中'
                            });
                            app.globalData.util.request({
                                url: 'entry/wxapp/SdDrShop',
                                cachetime: '0',
                                data: {
                                    id: e
                                },
                                success: function (t) {
                                    console.log(t.data);
                                    if ('1' == t.data) {
                                        uni.showToast({
                                            title: '锁定成功'
                                        });
                                        that.reLoad();
                                        setTimeout(function () {
                                            uni.navigateTo({
                                                url: 'smdcform?storeid=' + that.storeid + '&tableid=' + that.tableid + '&drid=' + e
                                            });
                                        }, 1000);
                                    }
                                }
                            });
                        } else {
                            if (t.cancel) {
                                console.log('用户点击取消');
                            }
                        }
                    }
                });
            }
        },

        jsdd: function () {
            var that = this;
            var t = this.drid;
            this.drlsit.drorder;
            uni.showLoading({
                title: '加载中'
            });
            app.globalData.util.request({
                url: 'entry/wxapp/JsDrShop',
                cachetime: '0',
                data: {
                    id: t
                },
                success: function (t) {
                    console.log(t.data);
                    if ('1' == t.data) {
                        uni.showToast({
                            title: '解锁成功'
                        });
                        that.reLoad();
                    }
                }
            });
        },

        sc: function (t) {
            var that = this;
            var e = this.storeid;
            var o = t.currentTarget.dataset.sonid;
            var s = this.zuid;
            var i = this.drid;
            console.log(e, s, o, i);
            uni.showModal({
                title: '提示',
                content: '确定删除他的商品吗？',
                success: function (t) {
                    if (t.confirm) {
                        console.log('用户点击确定');
                        app.globalData.util.request({
                            url: 'entry/wxapp/DelCar',
                            cachetime: '0',
                            data: {
                                store_id: e,
                                user_id: s,
                                son_id: o,
                                dr_id: i,
                                type: 2
                            },
                            success: function (t) {
                                console.log(t.data);
                                if ('1' == t.data) {
                                    uni.showToast({
                                        title: '删除成功'
                                    });
                                    that.reLoad();
                                }
                            }
                        });
                    } else {
                        if (t.cancel) {
                            console.log('用户点击取消');
                        }
                    }
                }
            });
        },

        sxsj: function () {
            this.reLoad();
        },

        reLoad: function () {
            var that = this;
            var t = this.storeid;
            var e = this.zuid;
            var o = this.drid;
            console.log(t, e, o);
            app.globalData.util.request({
                url: 'entry/wxapp/DrShopList',
                cachetime: '0',
                data: {
                    store_id: t,
                    user_id: e,
                    dr_id: o
                },
                success: function (t) {
                    console.log(t.data);
                    that.setData({
                        drlsit: t.data
                    });
                }
            });
        },

        formReset() {
            console.log('占位：函数 formReset 未声明');
        }
    }
};
</script>
<style>
@import './drdc.css';
</style>
